export default class messageMgr {
    static _Instance: messageMgr;
    private msgMap = {}
    static get Instance(): messageMgr {
        if (!this._Instance) {
            messageMgr._Instance = new messageMgr
        }
        return this._Instance;
    }


    // 事件系统
    // messageMgr.Instance.regMessage("del", () => {
    //     mainscene.Instance.visible = false;
    // })
    // Laya.stage.on(Laya.Event.DOUBLE_CLICK, this, () => {
    //     messageMgr.Instance.sendMessage("del")
    // })

    //=================================注册事件
    public regMessage(messagename: string, handle: any) {
        let hand = new Laya.Handler(this, handle)
        this.msgMap[messagename] = hand;
}

    //================================ 触发事件
    public sendMessage(messagename: string, params?: any) {
        let handle = this.msgMap[messagename] as Laya.Handler;
        if (params) {
            handle.runWith(params)
        } else {
            handle.run();
        }
    }

    public removeMessage(messagename: string) {
        this.msgMap[messagename] = null;
    }



}